#ifndef CAMERA_3D_APP_PLUGIN_H
#define CAMERA_3D_APP_PLUGIN_H

#include <ctkPluginActivator.h>

#include <QObject>
#include <QSharedDataPointer>

#include "Base/Interface/DockWidgetRegister.h"
#include "Base/data.h"
#include "ListenerPluginWidget.h"
#include "ctkPluginContext.h"
#include "ctkPluginFramework.h"
#include "service/event/ctkEventAdmin.h"
#include "service/event/ctkEventHandler.h"
class ListenerPlugin : public QObject,
                       public ctkEventHandler,
                       public IDockWidget {
  Q_OBJECT
  Q_INTERFACES(ctkEventHandler)
  Q_INTERFACES(IDockWidget)

 public:
  explicit ListenerPlugin(ctkPluginContext* context);
  ~ListenerPlugin();

  QWidget* CreateWidget() override;
  void InitWidget() override;
  QString GetDockObjectName() override;
  QString GetDockWidgetName() override;
  Qt::DockWidgetArea GetDockWidgetArea() override;
  QDockWidget::DockWidgetFeatures GetDockFeatures() override;

 protected:
  void handleEvent(const ctkEvent& event) override;

 private:
  void SendEvent(const QString topic, const ctkDictionary& obj);

 private:
  ctkPluginContext* ctk_plugin_context_;
  ListenerPluginWidget* listener_plugin_widget_;
};

class ListenerPluginActivator : public QObject, public ctkPluginActivator {
  Q_OBJECT
  Q_INTERFACES(ctkPluginActivator)
  Q_PLUGIN_METADATA(IID "EventListenerPlugin")
  // 向Qt的插件框架声明，希望将xxx插件放入到框架中。

 public:
  void start(ctkPluginContext* context) {
    qDebug() << "start ListenerPlugin----------";
    listener_plugin_ = new ListenerPlugin(context);

    ctkDictionary dict;
    context->registerService<IDockWidget>(listener_plugin_, dict);
  }
  void stop(ctkPluginContext* context) {
    if (listener_plugin_) {
      delete listener_plugin_;
      listener_plugin_ = nullptr;
    }
  }

 private:
  ListenerPlugin* listener_plugin_{nullptr};
};

#endif  // ROBOT_APP_PLUGIN_H
